package com.ehome.poct.base.dao.banner.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ehome.mybatisplus.autoconfigure.BaseEntityOld;
import com.ehome.poct.base.dao.banner.mapper.TestBannerExposureMapper;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * @description: 轮播图内容
 * @author: muqiu
 * @time: 2022/3/7 9:30
 */
@Data
@TableName(value = "test_conf_banner")
public class TestConfBannerDO extends BaseEntityOld<TestConfBannerDO> {

    /**
     * 主键
     */
    @TableId(value = "banner_item_id")
    private Long bannerItemId;
    /**
     * 图片地址
     */
    @TableField(value = "img_url")
    private String imgUrl;
    /**
     * 顺序
     */
    @TableField(value = "img_order")
    private Long imgOrder;
    /**
     * 广告名称
     */
    @TableField(value = "banner_name")
    private String bannerName;
    /**
     * 设备类型
     */
    @TableField(value = "device_type")
    private Integer deviceType;
    /**
     * 广告位置
     */
    @TableField(value = "banner_position")
    private Integer bannerPosition;
    /**
     * 开始时间
     */
    @TableField(value = "effect_time")
    private LocalDateTime effectTime;
    /**
     * 结束时间
     */
    @TableField(value = "invalid_time")
    private LocalDateTime invalidTime;
    /**
     * 广告状态
     */
    @TableField(value = "status")
    private Integer status;
    /**
     * 总曝光数
     */
    @TableField(value = "exposure_total")
    private Long exposureTotal;

    /**
     * 今日曝光数
     */
    @TableField(value = "exposure_today")
    private Long exposureToday;

    @TableField(exist = false)
    private Long exposureYesterday;

    public void setDictData(TestBannerExposureMapper testBannerExposureMapper) {
        this.exposureYesterday = Optional.ofNullable(testBannerExposureMapper.selectOne(Wrappers.<TestBannerExposureDO>lambdaQuery().eq(TestBannerExposureDO::getBannerItemId,this.bannerItemId).eq(TestBannerExposureDO::getDate
        ,LocalDate.now().minusDays(1)))).map(TestBannerExposureDO::getExposure).orElse(null);
    }

}
